package org.xyl.init;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import org.xyl.service.RagService;

/**
 * 应用初始化类
 */
@Component
public class ApplicationInitializer implements ApplicationRunner {
    
    private static final Logger logger = LoggerFactory.getLogger(ApplicationInitializer.class);
    
    @Autowired
    private RagService ragService;
    
    @Override
    public void run(ApplicationArguments args) throws Exception {
        logger.info("开始初始化RAG系统...");
        
        try {
            // 初始化知识库
            ragService.initializeKnowledgeBase();
            logger.info("RAG系统初始化完成");
        } catch (Exception e) {
            logger.error("RAG系统初始化失败", e);
            // 初始化失败不应该阻止应用启动，但应该记录严重错误
        }
    }
}